<!DOCTYPE html><html lang="zh-CN" data-theme="dark"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"><title>Elasticsearch 入门 | 铃仙小屋</title><meta name="author" content="Reisen"><meta name="copyright" content="Reisen"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#0d0d0d"><meta name="description" content="Elasticsearch 入门由于工作需要，所以不得不接触es。而且还要我写相关的工具类，虽然说照葫芦画瓢容易，但是了解到这个东西之后，就想好好学习以下。当然了也算作我的个人笔记，大部分都是看官方文章的记录，所以不会标注版权什么的，官方链接下面会有，想深入了解可以去看看。 es介绍 Elasticsearch是一个搜索引擎  下面简称为es  Elasticsearch 是一个分布式、免费和开放">
<meta property="og:type" content="article">
<meta property="og:title" content="Elasticsearch 入门">
<meta property="og:url" content="https://www.reisen7.cc/2023/02/24/Elasticsearch_%E5%85%A5%E9%97%A8/index.html">
<meta property="og:site_name" content="铃仙小屋">
<meta property="og:description" content="Elasticsearch 入门由于工作需要，所以不得不接触es。而且还要我写相关的工具类，虽然说照葫芦画瓢容易，但是了解到这个东西之后，就想好好学习以下。当然了也算作我的个人笔记，大部分都是看官方文章的记录，所以不会标注版权什么的，官方链接下面会有，想深入了解可以去看看。 es介绍 Elasticsearch是一个搜索引擎  下面简称为es  Elasticsearch 是一个分布式、免费和开放">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://s3.bmp.ovh/imgs/2023/02/24/bf33cc6c00297765.jpg">
<meta property="article:published_time" content="2023-02-24T14:01:09.000Z">
<meta property="article:modified_time" content="2024-04-15T03:18:16.191Z">
<meta property="article:author" content="Reisen">
<meta property="article:tag" content="Elasticsearch">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://s3.bmp.ovh/imgs/2023/02/24/bf33cc6c00297765.jpg"><link rel="shortcut icon" href="/img/amber.png"><link rel="canonical" href="https://www.reisen7.cc/2023/02/24/Elasticsearch_%E5%85%A5%E9%97%A8/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: {"limitDay":500,"position":"top","messagePrev":"It has been","messageNext":"days since the last update, the content of the article may be outdated."},
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":300},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":50,"languages":{"author":"作者: Reisen","link":"链接: ","source":"来源: 铃仙小屋","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: true,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Elasticsearch 入门',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2024-04-15 11:18:16'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          const now = new Date()
          const hour = now.getHours()
          const isNight = hour <= 6 || hour >= 18
          if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
          else if (t === 'light') activateLightMode()
          else activateDarkMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/css/custom.css" media="defer" onload="this.media='all'"><link rel="stylesheet" href="/css/universe.css"><!-- hexo injector head_end start --><link rel="stylesheet" href="https://cdn.cbd.int/hexo-butterfly-clock-anzhiyu/lib/clock.min.css" /><!-- hexo injector head_end end --><meta name="generator" content="Hexo 6.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>const preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',()=> { preloader.endLoading() })

if (true) {
  document.addEventListener('pjax:send', () => { preloader.initLoading() })
  document.addEventListener('pjax:complete', () => { preloader.endLoading() })
}</script><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="http://q1.qlogo.cn/g?b=qq&amp;nk=328170849&amp;s=640" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">6</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">5</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">1</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 休闲</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 图片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/comments/index.html"><i class="fa-fw fas fa-heartbeat"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://s3.bmp.ovh/imgs/2023/02/24/bf33cc6c00297765.jpg')"><nav id="nav"><span id="blog-info"><a href="/" title="铃仙小屋"><img class="site-icon" src="/img/amber.png"/><span class="site-name">铃仙小屋</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 休闲</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 图片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/comments/index.html"><i class="fa-fw fas fa-heartbeat"></i><span> 留言板</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Elasticsearch 入门</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-02-24T14:01:09.000Z" title="发表于 2023-02-24 22:01:09">2023-02-24</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2024-04-15T03:18:16.191Z" title="更新于 2024-04-15 11:18:16">2024-04-15</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E5%9F%BA%E7%A1%80/">基础</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">1.4k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>4分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Elasticsearch 入门"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="Elasticsearch-入门"><a href="#Elasticsearch-入门" class="headerlink" title="Elasticsearch 入门"></a>Elasticsearch 入门</h2><p>由于工作需要，所以不得不接触es。而且还要我写相关的工具类，虽然说照葫芦画瓢容易，但是了解到这个东西之后，就想好好学习以下。当然了也算作我的个人笔记，大部分都是看官方文章的记录，所以不会标注版权什么的，官方链接下面会有，想深入了解可以去看看。</p>
<h3 id="es介绍"><a href="#es介绍" class="headerlink" title="es介绍"></a>es介绍</h3><blockquote>
<p>Elasticsearch是一个搜索引擎</p>
</blockquote>
<p>下面简称为es</p>
<blockquote>
<p>Elasticsearch 是一个分布式、免费和开放的搜索和分析引擎，适用于所有类型的数据，包括文本、数字、地理空间、结构化和非结构化数据。 Elasticsearch 基于 Apache Lucene 构建，并于 2010 年由 Elasticsearch N.V. 首次发布（现在称为 Elastic）。Elasticsearch 以其简单的 REST API、分布式特性、速度和可扩展性而闻名，是 Elastic Stack 的核心组件，Elastic Stack 是一组用于数据摄取、丰富、存储、分析和可视化的免费开放工具。 通常被称为 ELK Stack。</p>
</blockquote>
<p>上面是官方原话，感兴趣的可以去看看。链接贴在这里</p>
<p><a target="_blank" rel="noopener" href="https://elasticstack.blog.csdn.net/article/details/98871531">Elasticsearch 简介</a></p>
<h3 id="es能做什么？"><a href="#es能做什么？" class="headerlink" title="es能做什么？"></a>es能做什么？</h3><blockquote>
<p>Elasticsearch 的速度和可扩展性及其为多种类型的内容编制索引的能力意味着它可用于多种用例：</p>
<p>应用搜索，比如我们常见的 github，linkedin，滴滴，美团，抖音，点评，音乐，视频，银行，证券，保险，电信 app 里的搜索<br>网站搜索<br>企业搜索<br>日志记录和日志分析<br>基础设施指标和容器监控<br>应用性能监控<br>地理空间数据分析和可视化<br>安全分析<br>商业分析</p>
</blockquote>
<p>公司平常就用这个存一些数据，比如日志什么。速度确实快</p>
<h4 id="es安装"><a href="#es安装" class="headerlink" title="es安装"></a>es安装</h4><p>公司用的是Linux，所以下面我会贴出win和Linux的安装方法。</p>
<h4 id="Java（JVM）版本"><a href="#Java（JVM）版本" class="headerlink" title="Java（JVM）版本"></a>Java（JVM）版本</h4><blockquote>
<p>Elasticsearch是使用Java构建的，包括JDK维护者的OpenJDK捆绑版本（GPLv2 + CE）。 在每个分布中。捆绑的 JVM 是推荐的 JVM 和 位于 Elasticsearch 主目录的目录中。jdk要使用您自己的 Java 版本，请设置环境变量。 如果必须使用与捆绑的 JVM 不同的 Java 版本。请看supported LTS version of Java</p>
</blockquote>
<p><img src="https://s3.bmp.ovh/imgs/2023/02/24/db05e724e6b8ad0e.png"></p>
<p>尽量选择LTS</p>
<h4 id="Windows安装"><a href="#Windows安装" class="headerlink" title="Windows安装"></a>Windows安装</h4><p>从该位置下载.zip 文件</p>
<p><a target="_blank" rel="noopener" href="https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.3.1-windows-x86_64.zip">地址</a></p>
<p>下载完找个舒服的地方解压就行惹</p>
<p><img src="https://s3.bmp.ovh/imgs/2023/02/24/a93cdd18e8c37f50.png"></p>
<p>在bin目录下找到 <code>elasticsearch.bat</code> 启动就好了。也可以通过cmd来启动，不过最好用管理员权限打开喔</p>
<p>然后我们在浏览器或者postman上面输入 <code>http://localhost:9200/</code> 会出现以下信息</p>
<p><img src="https://s3.bmp.ovh/imgs/2023/02/24/04571b8c08ba9a1b.png"></p>
<p>其中config里面的 <code>elasticsearch.yml</code> 是配置文件 里面的</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">network.host:</span> <span class="number">0.0</span><span class="number">.0</span><span class="number">.0</span></span><br></pre></td></tr></table></figure>

<p>如果你想让其他人访问es 可以改成0.0.0.0，这样会绑定成任意IP 而非localhost 。这里和redis改bind差不多</p>
<h4 id="Linux安装"><a href="#Linux安装" class="headerlink" title="Linux安装"></a>Linux安装</h4><p>下载：<a target="_blank" rel="noopener" href="https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-oss-7.3.0-linux-x86_64.tar.gz">地址</a></p>
<ol>
<li><p>创建用户</p>
<p>es禁止root用户启动，所以我们创建一个新用户es</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">adduser es</span><br><span class="line"><span class="comment">#修改密码</span></span><br><span class="line">passwes</span><br></pre></td></tr></table></figure>
</li>
<li><p>创建es的数据、日志目录</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#创建日志目录</span></span><br><span class="line"><span class="built_in">mkdir</span> -p /data/elasticsearch/logs</span><br><span class="line"></span><br><span class="line"><span class="comment">#授权</span></span><br><span class="line"><span class="built_in">chown</span> es:es -R /data/</span><br></pre></td></tr></table></figure>
</li>
<li><p>解压es安装包</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">tar -zxvf elasticsearch-oss-7.3.0-linux-x86_64.tar.gz</span><br></pre></td></tr></table></figure>
</li>
<li><p>授权</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">chown</span> es:es -R /opt/elasticsearch-oss-7.3.0-linux-x86_64</span><br></pre></td></tr></table></figure>

<p>将权限都给es这个用户</p>
</li>
<li><p>修改yml</p>
<p>在elasticsearch.yml中修改下面属性</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 集群名称</span></span><br><span class="line"><span class="attr">cluster.name:</span> <span class="string">ihbe-cluster</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 节点名称,其余两个节点分别为node-2 和node-3，别一样 （集群）</span></span><br><span class="line"><span class="attr">node.name:</span> <span class="string">node-1</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 指定该节点是否有资格被选举成为master节点，默认为true （集群）</span></span><br><span class="line"><span class="attr">node.master:</span> <span class="literal">true</span></span><br><span class="line"><span class="comment"># 允许该节点存储数据(默认开启)</span></span><br><span class="line"><span class="attr">node.data:</span> <span class="literal">true</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 索引数据的存储路径</span></span><br><span class="line"><span class="attr">path.data:</span> <span class="string">/data/elasticsearch/data</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 日志文件的存储路径</span></span><br><span class="line"><span class="attr">path.logs:</span> <span class="string">/data/elasticsearch/logs</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 绑定当前机器节点的IP地址, 其他节点配置自己的IP地址</span></span><br><span class="line"><span class="attr">network.host:</span> <span class="string">*.*.*.*</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 设置对外服务的http端口，默认为9200</span></span><br><span class="line"><span class="attr">http.port:</span> <span class="number">9200</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 设置节点间交互的tcp端口,默认为9300</span></span><br><span class="line"><span class="attr">transport.tcp.port:</span> <span class="number">9300</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#集群的所有机器节点的IP地址</span></span><br><span class="line"><span class="string">discovery.zen.ping.unicast.hosts:[&quot;*.*.*.*&quot;,&quot;*.*.*.*&quot;,&quot;*.*.*.*&quot;]</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#通过配置大多数节点(符合主节点数/ 2 + 1)来防止分裂。</span></span><br><span class="line"><span class="attr">discovery.zen.minimum_master_nodes:</span> <span class="number">2</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#设置为true锁住内存。因为内存交换到磁盘对服务器性能是致命的</span></span><br><span class="line"><span class="attr">bootstrap.memory_lock:</span> <span class="literal">true</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>修改jvm启动项</p>
<p>进入config，找到<code>jvm.options</code> vi进入编辑</p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 配置ES占用物理内存大小，根据具体机器本身大小来定，一半物理内存</span></span><br><span class="line"><span class="attr">-Xms20g</span></span><br><span class="line"></span><br><span class="line"><span class="attr">-Xmx20g</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment"># 修正CVE-2021-44228漏洞</span></span><br><span class="line"></span><br><span class="line"><span class="attr">-Dlog4j2.formatMsgNoLookups</span>=<span class="string">true   </span></span><br></pre></td></tr></table></figure>
</li>
<li><p>(集群) 拷贝目录到其他节点</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">scp -r /opt/elasticsearch root@*.*.*.*:/opt/</span><br></pre></td></tr></table></figure>
<p>注意这里的文件夹，是你安装的文件夹名，我这里简写了。不要直接复制改一改名字。<br><code>同时重复第5步操作，将yml里面的network.host</code>改成当前服务器的ip，然后<code>找到node.name:</code>改成其他名字，（与其他节点不重复）</p>
</li>
<li><p>启动服务<br>到安装es的节点下</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./bin/elasticsearch -d -p pid</span><br></pre></td></tr></table></figure>
<p>使用jps看是否启动</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">jps</span><br></pre></td></tr></table></figure></li>
<li><p>验证</p>
<p>在任意的服务器上面<br>验证集群</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -XGET <span class="string">&#x27;http://*.*.*.*:9200/_cat/nodes?pretty&#x27;</span></span><br></pre></td></tr></table></figure>
<p>如果能正确显示每个节点ip则成功</p>
<p>查询集群状态</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -XGET <span class="string">&#x27;http://*.*.*.*:9200/_cluster/nodes?pretty&#x27;</span></span><br></pre></td></tr></table></figure>
<p>在返回的json中，看<code>status</code>的值<br><code>-green</code>  正常，表示集群一切正常。<br><code>-yellow</code>  黄表示集群不可靠但可用，一般单节时候就是这个状态。<br><code>-red</code>  红表示集群不可用，有故障。</p>
<p>关闭es</p>
<p>使用jps查询进程ID<br>然后kill -9</p>
</li>
</ol>
</article><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Elasticsearch/">Elasticsearch</a></div><div class="post_share"><div class="social-share" data-image="https://s3.bmp.ovh/imgs/2023/02/24/bf33cc6c00297765.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2023/02/24/Java_%E5%85%A5%E9%97%A8/" title="Java 入门基础（一）"><img class="cover" src="https://s3.bmp.ovh/imgs/2023/02/25/1a3e9c86350e5726.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Java 入门基础（一）</div></div></a></div><div class="next-post pull-right"><a href="/2023/02/23/%E5%8D%9A%E5%AE%A2%E5%9F%BA%E7%A1%80%E7%94%A8%E6%B3%95/" title="博客基础用法"><img class="cover" src="https://pic3.zhimg.com/v2-7827197bfa0023932d428633d41372fd_250x0.jpg?source=172ae18b" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">博客基础用法</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#Elasticsearch-%E5%85%A5%E9%97%A8"><span class="toc-number">1.</span> <span class="toc-text">Elasticsearch 入门</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#es%E4%BB%8B%E7%BB%8D"><span class="toc-number">1.1.</span> <span class="toc-text">es介绍</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#es%E8%83%BD%E5%81%9A%E4%BB%80%E4%B9%88%EF%BC%9F"><span class="toc-number">1.2.</span> <span class="toc-text">es能做什么？</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#es%E5%AE%89%E8%A3%85"><span class="toc-number">1.2.1.</span> <span class="toc-text">es安装</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Java%EF%BC%88JVM%EF%BC%89%E7%89%88%E6%9C%AC"><span class="toc-number">1.2.2.</span> <span class="toc-text">Java（JVM）版本</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Windows%E5%AE%89%E8%A3%85"><span class="toc-number">1.2.3.</span> <span class="toc-text">Windows安装</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Linux%E5%AE%89%E8%A3%85"><span class="toc-number">1.2.4.</span> <span class="toc-text">Linux安装</span></a></li></ol></li></ol></li></ol></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2023 - 2024 By Reisen</div><div class="footer_custom_text">I wish you to become your own sun, no need to rely on who's light</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><div class="js-pjax"></div><canvas id="universe"></canvas><script defer src="/js/universe.js"></script><script defer="defer" id="fluttering_ribbon" mobile="true" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-fluttering-ribbon.min.js"></script><script id="click-show-text" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/click-show-text.min.js" data-mobile="false" data-text="I,LOVE,YOU" data-fontsize="15px" data-random="false" async="async"></script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/metingjs/dist/Meting.min.js"></script><script src="https://cdn.jsdelivr.net/npm/pjax/pjax.min.js"></script><script>let pjaxSelectors = ["head > title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show",".js-pjax"]

var pjax = new Pjax({
  elements: 'a:not([target="_blank"]):not([href="/music/"]):not([href="/no-pjax/"])',
  selectors: pjaxSelectors,
  cacheBust: false,
  analytics: false,
  scrollRestoration: false
})

document.addEventListener('pjax:send', function () {

  // removeEventListener scroll 
  window.tocScrollFn && window.removeEventListener('scroll', window.tocScrollFn)
  window.scrollCollect && window.removeEventListener('scroll', scrollCollect)

  document.getElementById('rightside').style.cssText = "opacity: ''; transform: ''"
  
  if (window.aplayers) {
    for (let i = 0; i < window.aplayers.length; i++) {
      if (!window.aplayers[i].options.fixed) {
        window.aplayers[i].destroy()
      }
    }
  }

  typeof typed === 'object' && typed.destroy()

  //reset readmode
  const $bodyClassList = document.body.classList
  $bodyClassList.contains('read-mode') && $bodyClassList.remove('read-mode')

  typeof disqusjs === 'object' && disqusjs.destroy()
})

document.addEventListener('pjax:complete', function () {
  window.refreshFn()

  document.querySelectorAll('script[data-pjax]').forEach(item => {
    const newScript = document.createElement('script')
    const content = item.text || item.textContent || item.innerHTML || ""
    Array.from(item.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value))
    newScript.appendChild(document.createTextNode(content))
    item.parentNode.replaceChild(newScript, item)
  })

  GLOBAL_CONFIG.islazyload && window.lazyLoadInstance.update()

  typeof chatBtnFn === 'function' && chatBtnFn()
  typeof panguInit === 'function' && panguInit()

  // google analytics
  typeof gtag === 'function' && gtag('config', '', {'page_path': window.location.pathname});

  // baidu analytics
  typeof _hmt === 'object' && _hmt.push(['_trackPageview',window.location.pathname]);

  typeof loadMeting === 'function' && document.getElementsByClassName('aplayer').length && loadMeting()

  // prismjs
  typeof Prism === 'object' && Prism.highlightAll()
})

document.addEventListener('pjax:error', (e) => {
  if (e.request.status === 404) {
    pjax.loadUrl('/404.html')
  }
})</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div><!-- hexo injector body_end start --><script data-pjax>
  function butterfly_clock_anzhiyu_injector_config(){
    var parent_div_git = document.getElementsByClassName('sticky_layout')[0];
    var item_html = '<div class="card-widget card-clock"><div class="card-glass"><div class="card-background"><div class="card-content"><div id="hexo_electric_clock"><img class="entered loading" id="card-clock-loading" src="https://cdn.cbd.int/hexo-butterfly-clock-anzhiyu/lib/loading.gif" style="height: 120px; width: 100%;" data-ll-status="loading"/></div></div></div></div></div>';
    console.log('已挂载butterfly_clock_anzhiyu')
    if(parent_div_git) {
      parent_div_git.insertAdjacentHTML("afterbegin",item_html)
    }
  }
  var elist = 'null'.split(',');
  var cpage = location.pathname;
  var epage = '/';
  var qweather_key = 'b16a1fa0e63c46a4b8f28abfb06ae3fe';
  var gaud_map_key = 'e2b04289e870b005374ee030148d64fd&s=rsv3';
  var baidu_ak_key = 'undefined';
  var flag = 0;
  var clock_rectangle = '113.34532,23.15624';
  var clock_default_rectangle_enable = 'false';

  for (var i=0;i<elist.length;i++){
    if (cpage.includes(elist[i])){
      flag++;
    }
  }

  if ((epage ==='all')&&(flag == 0)){
    butterfly_clock_anzhiyu_injector_config();
  }
  else if (epage === cpage){
    butterfly_clock_anzhiyu_injector_config();
  }
  </script><script src="https://widget.qweather.net/simple/static/js/he-simple-common.js?v=2.0"></script><script data-pjax src="https://cdn.cbd.int/hexo-butterfly-clock-anzhiyu/lib/clock.min.js"></script><!-- hexo injector body_end end --></body></html>